home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Virtual User / Virtual User Current Release / Examples / Example Libraries / QuickTasks.vulib < prev    next >
Encoding:
Text File  |  1998-06-04  |  14.9 KB  |  469 lines  |  [TEXT/MPS ]

  1. #
  2. #    File:        QuickTasks.vulib
  3. #
  4. #    Contains:    contains quick tasks for any scripts. 
  5. #
  6. #    Written by:    David Gaxiola
  7. #
  8. #    Copyright:    © 1992 by Apple Computer, Inc., all rights reserved.
  9. #
  10. #    Change History (most recent first):
  11. #
  12. #                 8/19/92    DGG            logging output made more readable
  13. #                 8/10/92    DGG            minor changes in variable names
  14. #                  8/4/92    DGG            "checkMethod" parameters removed.
  15. #                  7/7/92    DGG            comments added
  16. #                  6/17/92    DGG            creation 
  17. #
  18. #    To Do:
  19. #
  20.  
  21. Libraries "Time.vulib";
  22.  
  23. ### Logging Tasks
  24.  
  25. (************************************************************************************
  26. * Task LogNormal(outputString, printTime)
  27. *    Will send a given outputString as a comment to the output file, optionally
  28. *    including the current time.
  29. ************************************************************************************)
  30. task LogNormal(outputString := "", printTime := false)
  31. begin
  32.     if (printTime)
  33.         print "# At ", GetCurrentTime(), " - ";
  34.     if (not printTime)
  35.         print "# ";
  36.     println outputString;
  37. end;
  38.  
  39. (************************************************************************************
  40. * Task LogError(errorString, printTime)
  41. *    Will send a given errorString as a comment noted as being an error to the 
  42. *    output file, optionally including the current time.
  43. ************************************************************************************)
  44. task LogError(errorString := "", printTime := true)
  45. begin
  46.     if (printTime)
  47.         print "#--    Error at: ", GetCurrentTime(), " - ";
  48.     if (not printTime)
  49.         print "#--    Error: ";
  50.     println errorString;
  51. end;
  52.  
  53. (************************************************************************************
  54. * Task LogTime()
  55. *    Will send the current time to the output file.
  56. ************************************************************************************)
  57. task LogTime()
  58. begin
  59.     println "# The time is: ", GetCurrentTime();
  60. end;
  61.  
  62. ### Counting tasks.
  63.  
  64. (************************************************************************************
  65. * Task CountMenuItems(menuName)
  66. *    Will count the number of menu items in a menu specified by name.  If no menu
  67. *    is specified, the total number of menu items in all of the menus is counted.
  68. *    An integer is returned.
  69. ************************************************************************************)
  70. task CountMenuItems(menuName := undefined)
  71. begin
  72.     if (not menuName)
  73.     begin
  74.         allMenus := collect [menu];
  75.         runningTotal := 0;
  76.         for each singleMenu in allMenus
  77.             runningTotal := runningTotal + (card collect [menuItem m:singleMenu]);
  78.     end;
  79.     else
  80.         runningTotal := (card collect [menuItem m:menuName]!);
  81.     return runningTotal;
  82. end;
  83.  
  84. (************************************************************************************
  85. * Task CountMenus()
  86. *    Will count the number of menus in the current menubar.  An integer is returned
  87. ************************************************************************************)
  88. task CountMenus()
  89. begin
  90.     allMenus := collect [menu];
  91.     return (card allMenus);
  92. end;
  93.  
  94. (************************************************************************************
  95. * Task CountWindows()
  96. *    Will count the number of windows currently visible to VU.  An integer is
  97. *    returned.
  98. ************************************************************************************)
  99. task CountWindows()
  100. begin
  101.     allWindows := collect [window];
  102.     return (card allWindows);
  103. end;
  104.  
  105. (************************************************************************************
  106. * Task CountWindowItems(winName)
  107. *    Will count the number of content items currently visible to VU in a given
  108. *    window. The window is specified by title, otherwise the top windows is used
  109. *    as default. An integer is returned.
  110. ************************************************************************************)
  111. task CountWindowItems(winName := undefined)
  112. begin
  113.     if (not winName)
  114.         match [window o:1 k:?items];
  115.     else
  116.         match [window t:winName k:?items];
  117.     return (card items);
  118. end;
  119.  
  120. ### "Getting" tasks.
  121.  
  122. (************************************************************************************
  123. * Task GetMenuItemTitle(menuItemOrder, menuIdentifier)
  124. *    Will return the title of a menu item specified by order in a menu spefiecied
  125. *    either by order or title.  menuItemOrder specifies the menu item's order in the
  126. *    menu specified by menuIdentifier.  It will return the title in the form of a 
  127. *    string.
  128. ************************************************************************************)
  129. task GetMenuItemTitle(menuItemOrder := 1, menuIdentifier := 1)
  130. begin
  131.     if IsString(menuIdentifier)
  132.         match [menuItem t:?menuTitle o:menuItemOrder m:[menu t:menuIdentifier]];
  133.     else if IsInteger(menuIdentifier)
  134.         match [menuItem t:?menuTitle o:menuItemOrder m:[menu o:menuIdentifier]];
  135.     return menuTitle;
  136. end;
  137.  
  138. (************************************************************************************
  139. * Task GetMenuTitle(menuOrder)
  140. *    Will return the of a menu, given the menu's ordinality on the menubar.  A
  141. *    string is returned.  Defaults to the Apple menu.
  142. ************************************************************************************)
  143. task GetMenuTitle(menuOrder := 1)
  144. begin
  145.     match [menu t:?menuTitle o:menuOrder];
  146.     return menuTitle;
  147. end;
  148.  
  149. (************************************************************************************
  150. * Task GetTopWindow()
  151. *    Will return the descriptor of the topmost window visible to VU.
  152. ************************************************************************************)
  153. task GetTopWindow()
  154. begin
  155.     return match [window o:1];
  156. end;
  157.  
  158. (************************************************************************************
  159. * Task GetWindowTitle(winOrder)
  160. *    Will return the title of the window specified by its ordinality.  The default is
  161. *    the top window.  A string is returned.
  162. ************************************************************************************)
  163. task GetWindowTitle(winOrder := 1)
  164. begin
  165.     match [window t:?winTitle o:winOrder];
  166.     return winTitle;
  167. end;
  168.  
  169. ### Typing tasks.
  170.  
  171. (************************************************************************************
  172. * Task TypeWithXXX(keylist := {})
  173. *    All of the tasks beginning with "TypeWith" function in the same way.  They are
  174. *    passed a list of keys to type with the appropriate modifier key pressed at the
  175. *    same time.
  176. ************************************************************************************)
  177. task TypeWithCommand(keylist := {})
  178. begin
  179.     pressKey k:{commandKey};
  180.     type k:keylist;
  181.     releaseKey k:{commandKey};
  182. end;
  183.  
  184. task TypeWithOption(keylist := {})
  185. begin
  186.     println "blah!";
  187.     pressKey k:{optionKey};
  188.     type k:keylist;
  189.     releaseKey k:{optionKey};
  190. end;
  191.  
  192. task TypeWithControl(keylist := {})
  193. begin
  194.     pressKey k:{controlKey};
  195.     type k:keylist;
  196.     releaseKey k:{controlKey};
  197. end;
  198.  
  199. task TypeWithCommandOption(keylist := {})
  200. begin
  201.     pressKey k:{commandKey, optionKey};
  202.     type k:keylist;
  203.     releaseKey k:{commandKey, optionKey};
  204. end;
  205.  
  206. task TypeWithCommandControl(keylist := {})
  207. begin
  208.     pressKey k:{commandKey, controlKey};
  209.     type k:keylist;
  210.     releaseKey k:{commandKey, controlKey};
  211. end;
  212.  
  213. task TypeWithOptionControl(keylist := {})
  214. begin
  215.     pressKey k:{optionKey, controlKey};
  216.     type k:keylist;
  217.     releaseKey k:{optionKey, controlKey};
  218. end;
  219.  
  220. task TypeWithCommandOptionControl(keylist := {})
  221. begin
  222.     pressKey k:{commandKey, optionKey, controlKey};
  223.     type k:keylist;
  224.     releaseKey k:{commandKey, optionKey, controlKey};
  225. end;
  226.  
  227. ### Waiting tasks.
  228.  
  229. (************************************************************************************
  230. * Task WaitForMatch( WhatToMatch, MaxWait := 60 )
  231. *    This task will wait in a loop until a match for the descriptor provided 
  232. *    in WhatToMatch succeeds or MaxWait seconds have elapsed.
  233. *    WhatToMatch is any descriptor.
  234. *    MaxWait is the maximum number of seconds to wait.
  235. *    If the match succeeds before MaxWait seconds, true is returned
  236. *    If the match does not succeeds within MaxWait seconds, false is returned
  237. ************************************************************************************)
  238. task WaitForMatch( WhatToMatch, MaxWait := 60 )
  239. begin
  240.     count := 0;
  241.     while (not match WhatToMatch! ) and ( count <= maxWait )
  242.     begin
  243.         wait(1);                # prevent too tight of a loop
  244.                                 # prevents flooding the network
  245.         count := count + 1;
  246.     end;
  247.     
  248.     if ( count <= maxWait )
  249.         return true;
  250.     else
  251.         return false;
  252. end;
  253.  
  254. (************************************************************************************
  255. * Task WaitForNoMatch( WhatToMatch, MaxWait := 60 )
  256. *    This task will wait in a loop until a match for the descriptor provided 
  257. *    in WhatToMatch fails or MaxWait seconds have elapsed.
  258. *    WhatToMatch is any descriptor.
  259. *    MaxWait is the maximum number of seconds to wait.
  260. *    If the match fails before MaxWait seconds, true is returned
  261. *    If the match does not fail within MaxWait seconds, false is returned
  262. ************************************************************************************)
  263. task WaitForNoMatch( WhatToMatch, MaxWait := 60 )
  264. begin
  265.     count := 0;
  266.     while ( match WhatToMatch! ) and ( count <= maxWait )
  267.     begin
  268.         wait(1);                # prevent too tight of a loop
  269.                                 # prevents flooding the network
  270.         count := count + 1;
  271.     end;
  272.     
  273.     if ( count <= maxWait )
  274.         return true;
  275.     else
  276.         return false;
  277. end;
  278.  
  279. ### "IS" tasks
  280.  
  281. (************************************************************************************
  282. * Task IsXXX()
  283. *    All of these tasks function in the same way.  Each task is given an expression
  284. *    which it will check if it evaluates to a particular type.  If it does evaluate
  285. *    then true is returned, otherwise, false is returned.
  286. ************************************************************************************)
  287. task IsDescriptor(expr)
  288. begin
  289.     if typeOf(expr) = 'descriptor'
  290.         return true;
  291.     else 
  292.         return false;
  293. end;
  294.  
  295. task IsInteger(expr)
  296. begin
  297.     if typeOf(expr) = 'integer'
  298.         return true;
  299.     else 
  300.         return false;
  301. end;
  302.  
  303. task IsList(expr)
  304. begin
  305.     if typeOf(expr) = 'list'
  306.         return true;
  307.     else
  308.         return false;
  309. end;
  310.  
  311. task IsRegExpr(expr)
  312. begin
  313.     if typeOf(expr) = 'regularExpression'
  314.         return true;
  315.     else 
  316.         return false;
  317. end;
  318.  
  319. task IsString(expr)
  320. begin
  321.     if typeOf(expr) = 'string'
  322.         return true;
  323.     else 
  324.         return false;
  325. end;
  326.  
  327. task IsSymbol(expr)
  328. begin
  329.     if typeOf(expr) = 'symbol'
  330.         return true;
  331.     else 
  332.         return false;
  333. end;
  334.  
  335. ### Item checked/enabled tasks
  336.  
  337. (************************************************************************************
  338. * Task XXXEnabled/Selected/Checked(descriptorTrait)
  339. *    All of these tasks function in the same way.  The tasks are given a descriptorTrait
  340. *    specifying what to use as a base for the match operation.  The descriptorTrait is 
  341. *    either a string or an integer, depending on the type of the descriptorTrait.  
  342. *    These tasks will "intelligently" tell the difference between a string and an 
  343. *    integer and take the appropriate action.  The task will return a boolean 
  344. *    depending logically on whether the object is enabled, selected, or checked.
  345. ************************************************************************************)
  346. task ButtonEnabled(descriptorTrait := "")
  347. begin
  348.     if IsString(descriptorTrait)
  349.         match [button t:descriptorTrait e:?buttonEnabledState w:[window o:1]];
  350.     else if IsInteger(descriptorTrait)
  351.         match [button o:descriptorTrait e:?buttonEnabledState w:[window o:1]];
  352.     return buttonEnabledState;
  353. end;
  354.  
  355. task CheckBoxEnabled(descriptorTrait := "")
  356. begin
  357.     if IsString(descriptorTrait)
  358.         match [checkBox t:descriptorTrait e:?boxEnabledState w:[window o:1]];
  359.     else if IsInteger(descriptorTrait)
  360.         match [checkBox o:descriptorTrait e:?boxEnabledState w:[window o:1]];
  361.     return boxEnabledState;
  362.  
  363. end;
  364.  
  365. task MenuEnabled(descriptorTrait := "")
  366. begin
  367.     if IsString(descriptorTrait)
  368.         match [menu t:descriptorTrait e:?menuEnabledState];
  369.     else if IsInteger(descriptorTrait)
  370.         match [menu o:descriptorTrait e:?menuEnabledState];
  371.     return menuEnabledState;
  372. end;
  373.  
  374. task MenuItemEnabled(descriptorTrait := "")
  375. begin
  376.     if IsString(descriptorTrait)
  377.         match [menuItem t:descriptorTrait e:?menuItemEnabledState];
  378.     else if IsInteger(descriptorTrait)
  379.         match [menuItem o:descriptorTrait e:?menuItemEnabledState];
  380.     return menuItemEnabledState;
  381. end;
  382.  
  383. task CheckBoxChecked(descriptorTrait := "")
  384. begin
  385.     if IsString(descriptorTrait)
  386.         match [checkBox t:descriptorTrait s:?buttonStyle w:[window o:1]];
  387.     else if IsInteger(descriptorTrait)
  388.         match [checkBox o:descriptorTrait s:?buttonStyle w:[window o:1]];
  389.     if (buttonStyle[1] = 1)
  390.         buttonSelected := true;
  391.     else
  392.         buttonSelected := false;
  393.     return buttonSelected;
  394. end;
  395.  
  396. task RadioButtonSelected(descriptorTrait := "")
  397. begin
  398.     if IsString(descriptorTrait)
  399.         match [radioButton t:descriptorTrait s:?buttonStyle w:[window o:1]];
  400.     else if IsInteger(descriptorTrait)
  401.         match [radioButton o:descriptorTrait s:?buttonStyle w:[window o:1]];
  402.     if (buttonStyle[1] = 1)
  403.         buttonSelected := true;
  404.     else
  405.         buttonSelected := false;
  406.     return buttonSelected;
  407. end;
  408.  
  409. ### SelectionTasks
  410.  
  411. (************************************************************************************
  412. * Task SelectRectangle(theRectangle)
  413. *    This task is given the bounding rectangle of the object that is to be selected.
  414. *    SelectUnsupported will then move to the center of the rectangle and click on it.
  415. *    Nothing is returned.
  416. ************************************************************************************)
  417. task SelectRectangle(theRectangle := {0, 0, 1, 1})
  418. begin
  419.     xAvg := (theRectangle[1] + theRectangle[3]) / 2;
  420.     yAvg := (theRectangle[2] + theRectangle[4]) / 2;
  421.     move a:{xAvg, yAvg};
  422.     click;
  423. end;
  424.  
  425. (************************************************************************************
  426. * Task DoCheckBox(descriptorTrait)
  427. *    This task takes descriptorTraits in the same manner as the XXXEnabled tasks do. 
  428. *    Given a descriptorTrait this task will ensure that the specified checkBox
  429. *    is checked.
  430. ************************************************************************************)
  431. task DoCheckBox(descriptorTrait := "")
  432. begin
  433.     if (not CheckBoxChecked(descriptorTrait))
  434.         if IsString(descriptorTrait)
  435.             select [checkBox t:descriptorTrait w:[window o:1]];
  436.         else if IsInteger(descriptorTrait)
  437.             select [checkBox o:descriptorTrait w:[window o:1]];
  438. end;
  439.  
  440. (************************************************************************************
  441. * Task UnCheckBox(descriptorTrait)
  442. *    This task takes descriptorTraits in the same manner as the XXXEnabled tasks do. 
  443. *    Given a descriptorTrait, this task will ensure that the specified checkBox is 
  444. *    not checked.
  445. ************************************************************************************)
  446. task UnCheckBox(descriptorTrait := "")
  447. begin
  448.     if CheckBoxChecked(descriptorTrait)
  449.         if IsString(descriptorTrait)
  450.             select [checkBox t:descriptorTrait w:[window o:1]];
  451.         else if IsInteger(descriptorTrait)
  452.             select [checkBox o:descriptorTrait w:[window o:1]];
  453. end;
  454.  
  455. (************************************************************************************
  456. * Task DoSelectRadioButton(descriptorTrait)
  457. *    This task takes descriptorTraits in the same manner as the XXXEnabled tasks do. 
  458. *    Given a descriptorTrait, this task will ensure that the specified checkBox is 
  459. *    checked.
  460. ************************************************************************************)
  461. task DoSelectRadioButton(descriptorTrait := "")
  462. begin
  463.     if (not RadioButtonSelected(descriptorTrait))
  464.         if IsString(descriptorTrait)
  465.             select [radioButton t:descriptorTrait w:[window o:1]];
  466.         else if IsInteger(descriptorTrait)
  467.             select [radioButton o:descriptorTrait w:[window o:1]];
  468. end;
  469.